package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_activity.bp_blood_pressure.bp_view

import android.content.Intent
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.base.BpBaseActivity
import com.bp.hearthealth.pulse.lnapps.bp_extension.UIHelperBp
import com.bp.hearthealth.pulse.lnapps.bp_ui.bp_activity.bp_main.BpMainActivity
import com.bp.hearthealth.pulse.lnapps.bp_ui.bp_fragment.bp_tracker.blood_pressure.BloodPressureFragment
import com.bp.hearthealth.pulse.lnapps.bp_utils.Constants
import com.bp.hearthealth.pulse.lnapps.bp_utils.throttleClick
import com.bp.hearthealth.pulse.lnapps.databinding.ActivityBloodPressureViewBgBinding
import com.gyf.immersionbar.ImmersionBar

class BloodPressureViewActivity : BpBaseActivity<ActivityBloodPressureViewBgBinding>() {

    private var bloodPressureFragment: BloodPressureFragment? = null
    override fun initData() {
        super.initData()
        switchFragment()
//        binding.tvAddRecord.setOnClickListener(object : DoubleClickListener() {
//            override fun onNoDoubleClick(v: View?) {
//                startActivity(Intent(activity, BpBloodPressureNewRecordActivity::class.java))
//                finish()
//            }
//        })
    }

    private fun switchFragment() {
        supportFragmentManager.beginTransaction().apply {
            bloodPressureFragment?.let { this.hide(it) }
            if (bloodPressureFragment == null) {
                bloodPressureFragment =
                    BloodPressureFragment.newInstance(Constants.BLOOD_PRESSURE_ACTIVITY)
                add(R.id.tracker_fragment_container, bloodPressureFragment!!)
            } else {
                show(bloodPressureFragment!!)
            }
        }.commit()
    }

    override fun initImmersionBar() {
        super.initImmersionBar()
        binding.includeView.apply {
            tvBack.throttleClick {
                val intent = Intent(activity, BpMainActivity::class.java)
                startActivity(intent)
                finish()
            }
            tvBack.text = UIHelperBp.getString(R.string._blood_pressure_str)
            ImmersionBar.with(this@BloodPressureViewActivity).titleBar(toolbar).init()
        }
    }
}